package utils;

import pojo.entity.Record;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class GetLineChart {

    public int[] getUserDate(List<Record> records){
        /*获取当前日期*/
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());					//放入Date类型数据
        int day = calendar.get(Calendar.DATE);//获取日
        System.out.println("今天："+day+"号");

        int[] days=new int[7];

        for (int i = 6; i >= 0; i--) {
            days[i] = day--;
            System.out.println("第："+days[i]+"号");
        }
        return days;
    }

    public int[] getUserLoginAndRegister(List<Record> records){

        /*获取当前日期*/
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());					//放入Date类型数据
        int day = calendar.get(Calendar.DATE);//获取日
//        System.out.println("今天："+day+"号");

        int[] days=new int[7];

        records.forEach(item->{
            Date createTime = item.getCreateTime();
            Calendar calendar1 = Calendar.getInstance();
            calendar1.setTime(createTime);					//放入Date类型数据
            int day1 = calendar1.get(Calendar.DATE);

            int i=day-day1;
            if (i<7){
                days[i]++;
            }
        });

        /*System.out.println("common.utils.GetLineChart:LoginAndRegister:days:"+days[0]);
        System.out.println("common.utils.GetLineChart:days:"+days[1]);
        System.out.println("common.utils.GetLineChart:days:"+days[2]);*/

        for (int i = 0; i < days.length / 2; i++) {
            //进行数组互换
            int sum = days[i];
            days[i] = days[days.length - 1 - i];
            days[days.length - 1 - i] = sum;
        }

        return days;
    }

    public int[] getUserOrder(List<Record> records){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());					//放入Date类型数据
        int day = calendar.get(Calendar.DATE);//获取日
//        System.out.println("今天："+day+"号");

        int[] days=new int[7];

        records.forEach(item->{
            Date createTime = item.getCreateTime();
            Calendar calendar1 = Calendar.getInstance();
            calendar1.setTime(createTime);					//放入Date类型数据
            int day1 = calendar1.get(Calendar.DATE);
            Integer sumOrder = item.getSumOrder();
//            System.out.println("数据:"+sumOrder);
            int i=day-day1;
            if (i<7){
                days[i] += sumOrder;
//                System.out.println("qwe"+i);
            }

        });
        /*System.out.println("common.utils.GetLineChart:Order:days:"+days[0]);
        System.out.println(days[1]);
        System.out.println(days[2]);*/

        for (int i = 0; i < days.length / 2; i++) {
            //进行数组互换
            int sum = days[i];
            days[i] = days[days.length - 1 - i];
            days[days.length - 1 - i] = sum;
        }

        return days;
    }

    public int[] getUserGood(List<Record> records){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());					//放入Date类型数据
        int day = calendar.get(Calendar.DATE);//获取日
//        System.out.println("今天："+day+"号");

        int[] days=new int[7];

        records.forEach(item->{
            Date createTime = item.getCreateTime();
            Calendar calendar1 = Calendar.getInstance();
            calendar1.setTime(createTime);					//放入Date类型数据
            int day1 = calendar1.get(Calendar.DATE);
            Integer sumGood = item.getSumGood();
//            System.out.println("数据:"+sumGood);
            int i=day-day1;
            if (i<7){
                days[i] += sumGood;
//                System.out.println("qwe"+i);
            }

        });
        /*System.out.println("common.utils.GetLineChart:Good:days:"+days[0]);
        System.out.println(days[1]);
        System.out.println(days[2]);*/

        for (int i = 0; i < days.length / 2; i++) {
            //进行数组互换
            int sum = days[i];
            days[i] = days[days.length - 1 - i];
            days[days.length - 1 - i] = sum;
        }

        return days;
    }

}
